/*
 * Copyright 2008 Wilfred Springer
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.agilejava.javaone.tools;

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.antlr.stringtemplate.StringTemplate;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.kohsuke.args4j.Option;

import com.agilejava.javaone.CplanSessionCatalog;
import com.agilejava.javaone.Session;
import com.agilejava.javaone.SessionCatalog;

public class RawDownloadTool extends AbstractJavaOneTool {

    @Option(name = "-o", usage = "The output file", required = true)
    private File out;

    public final static void main(String[] args) {
        execute(new RawDownloadTool(), args);
    }

    @Override
    public void execute(ErrorHandler handler) {
        try {
            StringTemplate template = new StringTemplate(IOUtils
                    .toString(RawDownloadTool.class.getResourceAsStream("/simple.st")));
            List<? extends Session> sessions = getSessions();
            template.setAttribute("sessions", sessions);
            FileUtils.writeStringToFile(out, template.toString());
        } catch (IOException e) {
            handler.error(e.getMessage());
        }
    }

    @Override
    public String getName() {
        return "j108raw";
    }

    @Override
    public SessionCatalog getCatalog() {
        return new CplanSessionCatalog(20);
    }

}
